﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using IBatisNet.DataMapper;
using System.Data;

namespace WS
{
    using WS.Domain;
    /// <summary>
    /// Summary description for WS_Thanhvien
    /// </summary>
    [WebService(Namespace = "WS")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WS_Thanhvien : System.Web.Services.WebService
    {
        ISqlMapper sqlMapper;
        List<Thanhvien> list;

        public WS_Thanhvien()
        {
            sqlMapper = Mapper.Instance();
        }

        #region Web Method Thành viên Base

            [WebMethod]
            public List<Thanhvien> ReadList()
            {
                list = (List<Thanhvien>)sqlMapper.QueryForList<Thanhvien>("getThanhvien",null);
                return list;
            }

            [WebMethod]
            public bool InsertThanhvien(Thanhvien Thanhvien)
            {
                try
                {
                    sqlMapper.Insert("insertThanhvien",Thanhvien);
                    return true;
                }
                catch (Exception) { return false; }
            }

            [WebMethod]
            public bool UpdateThanhvien(Thanhvien Thanhvien)
            {
                try
                {
                    sqlMapper.Update("updateThanhvien", Thanhvien);
                    return true;
                }
                catch (Exception) { return false; }
            }

            [WebMethod]
            public bool DeleteThanhvien(int id) 
            {
                try
                {
                    sqlMapper.Delete("deleteThanhvien", id);
                    return true;
                }
                catch (Exception) { return false; }
            }

        #endregion

        #region Web Method Thành viên Support

            [WebMethod]
            public List<Thanhvien> CheckThanhvien(Thanhvien tv)
            {
                try
                {
                    list = (List<Thanhvien>)sqlMapper.QueryForList<Thanhvien>("checkThanhvien", tv);
                    return list;
                }
                catch (Exception) { return null; }
            }

        #endregion
        
    }
}
